Repository navigation
feat(unbind): say whether a USDC approval to the agent's wallet is still live on chain (R4) - #1559
Conversation
…ill live on chain Unbinding writes revoked_at and nothing else. In AGENT_SPEND_SOURCE=wallet the owner gave the agent's wallet a USDC approval, and only the owner's wallet can lower it, so the approval outlives the unbind. This server already refuses every spend by an unbound agent, but the agent wallet's key is still custodied here, so the unbind answer now reads the allowance from the chain and states it, with how to end it (USDC.approve(agentWallet, 0)). Stake mode has no approval and reads 0. A failed read (RPC down, wrong chain, timeout, unreadable agent row) is NOT_CHECKED and says the approval may still be live; never "0". The revoke itself is unchanged and happens first. Measured 2026-11-16 (block 59404267): every owner -> agent wallet pair on record, the one revoked binding included, reads 0; the E2E runs so far used stake mode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strix Security ReviewTo fix before merging (1)
PR summary: Makes the agent-unbind endpoint report whether the owner's on-chain USDC approval to that agent's wallet is still live: after revoking the binding it reads allowance(owner, agentWallet) from Base Sepolia (10 s bound) and adds an `onchain_approval` field stating the amount and how to zero it, or a "not checked" reason when the read cannot be trusted. Review summaryReviewed the unbind receipt change end to end: the new 1 resolved findingRuled out (3)
Review history (3)
Fixed the findings? re-run the review, or tag Review 3 on this PR · Reviewed by Strix |
… on #1559) ethers puts the request URL in its error message, and a provider URL can carry an API key, so the unbind answer now says only 'the RPC read failed' or 'did not answer in time'; the raw text goes to the server log. Test fails on the previous source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Reviewed the unbind receipt change end to end: the new approvalAfterUnbind reader, its wiring into DELETE /human/bind/:agentId, and the accompanying tests. The previous review's finding that a failed chain read returned the raw ethers error (and with it the configured RPC provider URL and any key inside it) is fixed in this commit — the catch block now reduces the failure to a fixed two-word reason, sends the raw text only to the server log, and a regression test asserts no URL or key can appear in the response. No new security issues were found: the added work all runs after the existing wallet-proof ownership gate, reads only the agent that gate just proved the caller owns, exposes no value that is not already public or already the caller's own, and every failure path fails closed to "not checked, may still be live" rather than to a claim that nothing is approved. One pre-existing raw database error echo sits a few lines above the changed code in the same handler; it was weighed and found to be outside this pull request's changes and reach, leaking only the caller's own input.
Reviewed by Strix
Configure security review settings
…sion after the in-lock re-check - No chain, DB, relay or credit error text reaches a gasless answer; it is logged server-side. ethers puts the request URL in its messages and a provider URL can carry an API key (the class Strix found on #1559). depositStake's error can carry verifyDeposit's raw RPC text too, so it is logged. - The admission slot is now taken after the in-lock authorizationState re-check, just before the relay, so a concurrent replay refused there uses no slot (Grok r3 on #1558). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Grok review (fenced lane) round 2 on
|
| Grok | Finding | Adjudication |
|---|---|---|
| R3-1 (high) | src/routes/v1/byok.ts:623: if the repid_agents read returns no error and no row, a null wallet goes into approvalAfterUnbind, which answers checked: true, live: false, 0.0 ("this agent has no wallet"). No wallet was read and no chain was queried. |
Confirmed, severity low. The spec allows "no approval" only for a row read successfully with no wallet; a missing row is not that. It is reachable only in a race. human_agent_bindings.agent_id is FOREIGN KEY … REFERENCES repid_agents(id) ON DELETE CASCADE [V], and 0 of the 7 bindings lack an agent row [V], so the row exists when the owner is read. It can be missing only if the agent is deleted between the owner read and the wallet read. |
The no-echo change itself: no finding.
Fix: a missing agent row answers checked: false with a fixed reason. The fix will come with a test that fails on this head and a new Grok round, both on the new SHA.
Not merged, and auto-merge is off.
… (Grok r2 on #1559) The unbind route passed a missing repid_agents row to approvalAfterUnbind as a null wallet, which answers "this agent has no wallet, so no approval can exist" without reading anything. The binding's FK cascades from repid_agents, so the row can be missing only if the agent is deleted between the owner read and the wallet read, but the statement was still false there. approvalForAgentRow now owns the three cases: read error or no row -> NOT_CHECKED (no chain read); a row with no wallet -> no approval; a row with a wallet -> read the chain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@strix-security please re-review head a381261 (fix for Grok r2 R3-1: a missing agent row on unbind is NOT_CHECKED). |
Grok review (fenced lane) round 3 on
|
#1558) * feat(stake): gasless owner deposit via USDC EIP-3009 (GASLESS_DEPOSIT_MODE, default off) A newcomer has testnet USDC and no ETH. The owner signs a transferWithAuthorization (owner -> stake escrow) in their wallet; POST /api/v1/stake/deposit/gasless checks it, the escrow submits it and pays the gas, and depositStake's verified path credits it. Nothing new verifies a signature: verifyEip3009Local (the x402 path) checks it against USDC's name/version read from the chain and matched to its DOMAIN_SEPARATOR (resolveAndVerifyDomain). The send is the escrow's guarded path: realSender's body is now escrowCall, shared by the refund, the stake payout and the relay, and the relay joins the same one-at-a-time queue (one nonce). Refused before the escrow spends gas: wrong recipient, zero amount, expired or expiring within 120 s, bad signature, no account for the payer, nonce already used on chain (replay), balance too low, any unreadable read. A concurrent second submission of one authorization is serialized and refused. off: refused without reading. shadow: every check, nothing sent. on: submit, credit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(stake): a gasless deposit whose credit throws still returns its tx hash (Grok r1 lead on #1558) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(stake): gasless deposits have a 1 USDC floor and a bounded share of the escrow queue (Strix on #1558) The keyless route refused only value <= 0, so a 1-micro-USDC authorization made the escrow pay a full transaction; and the per-authorization lock never makes two different authorizations wait, so a caller could queue more escrow sends than one signer drains, ahead of refunds and agent payouts. - MIN_GASLESS_DEPOSIT = 1 USDC, refused before any send. - createGaslessAdmission(4/min), process-wide, injected as deps.admit: past it, 429 escrow_busy and nothing is queued. Shadow mode and refused deposits use no admission. Not changed: depositStake and the owner-signed withdraw have no floor of their own; withdrawal needs the owner's signature, so it is not this keyless path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(stake): gasless answers never carry chain/relay error text; admission after the in-lock re-check - No chain, DB, relay or credit error text reaches a gasless answer; it is logged server-side. ethers puts the request URL in its messages and a provider URL can carry an API key (the class Strix found on #1559). depositStake's error can carry verifyDeposit's raw RPC text too, so it is logged. - The admission slot is now taken after the in-lock authorizationState re-check, just before the relay, so a concurrent replay refused there uses no slot (Grok r3 on #1558). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(stake): one gasless admission slot per payer per minute, on top of the global cap (Strix on #1558) One wallet could take all 4 global slots with concurrent deposits the escrow then refused, keeping the keyless route at 429 for everyone else. createGaslessAdmission(4, 1) now also bounds each payer (case-insensitive) to 1 a minute; rotating wallets still meets the global cap, and each wallet needs an account and the USDC it signs for. Tests fail on the previous source. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(stake): name the per-payer admission variable for what it holds (a wallet), not 'key' credential-safety-architecture flagged `r.payer === key` as a secret comparison. It compares wallet addresses, so the variable is renamed rather than allowlisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Owner action
You decide (MAJOR: changes what the unbind answer tells an owner about their money). Draft. Do not auto-merge. No flag: the unbind still revokes exactly as before, and its JSON gains one field,
onchain_approval.The question (W5)
In wallet mode (
AGENT_SPEND_SOURCE=wallet), the owner gives each agent wallet a USDC approval. Does an unbind leave that approval live on chain?Yes, by construction [V code].
DELETE /api/v1/human/bind/:agentIdcallsrevokeBinding, which writesrevoked_aton the binding and nothing else. An ERC-20 approval changes only when the owner's wallet callsapprove, or when the spender uses it up. The engine cannot set it to 0, because that needs the owner's signature.What already stops misuse: the spend route refuses every spend by an unbound agent (
not_bound), and a later owner's spends draw from that owner's wallet, not the old one. But the agent wallet's key is still custodied by the engine, so "nothing can spend it" is a claim about this code, not about the chain.Today [V on chain, block 59404267, read-only]: every owner → agent-wallet pair on record (7, including the one revoked binding) has allowance 0. The E2E runs so far used stake mode, which has no approval at all. So nothing is exposed now; this is about the first wallet-mode owner.
The fix: the receipt states it plainly
After a successful revoke, the answer reads
allowance(owner, agentWallet)from Base Sepolia (bounded at 10 s) and adds:{ checked: true, live: true, allowance_usdc, agent_wallet, statement, how_to_end }: "Unbinding does not change your on-chain USDC approval… up to X USDC… stays live until your wallet sets it to 0". How to end it:USDC.approve(<agent wallet>, 0).{ checked: true, live: false, allowance_usdc: "0.0" }: nothing live (stake mode).{ checked: false, reason }: RPC down, wrong chain, timeout, or an unreadable agent row. It says the approval may still be live, never "0".Tests
tests/unbind-approval.test.ts, 6 tests: live approval stated with amount and the exact call; 0 in stake mode; failed read, wrong chain, missing owner wallet and timeout are all NOT_CHECKED. Together with the existingagent-spend,agent-spend-from-stakeandauth-agent-spend-pathsuites: 86/86.tsc --noEmitclean. The function is new, so the test fails onorigin/mainat import. Route wiring is one call afterrevokeBinding; no route test exists for unbind, because its auth (principalOf) needs a wallet-signed request.Grok review (fenced lane, v4)
r1 on
aec2d617: NO_FINDINGS (spec: who may unbind unchanged; "nothing live" only after a successful read on chain 84532 that returned 0, or a successfully read agent row with no wallet; every failure NOT_CHECKED; a non-zero allowance stated withapprove(agentWallet, 0)).Strix (LOW): confirmed, fixed in
1a4e4b54. On a failed read, the unbind answer echoed the raw ethers error, which embeds the request URL and so any API key in a provider URL. The reason is now classified ("the RPC read failed" / "did not answer in time"), and the raw text goes only to the server log. A test with a keyed URL in the error fails on the previous source; 7/7 pass. Threads replied to and resolved. No Grok round covers1a4e4b54yet.Not done (follow-up if you want "sets it to 0 in the same flow")
USDC on Base Sepolia is FiatToken v2, which supports EIP-2612
permit. The owner could signpermit(owner, agentWallet, 0, deadline)at unbind, and the escrow could submit it gaslessly. That is the same pattern as the gasless deposit (#1558). I kept this PR to the statement because it needs no new signature flow, and stake mode (the default) has nothing to zero.🤖 Generated with Claude Code